﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Himp.Platform.Migrations
{
    /// <inheritdoc />
    public partial class add_table_StdEventModelDict : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_MainStdModelAssocPhrDict_MainStdModelDict_StdModelDictId",
                table: "MainStdModelAssocPhrDict");

            migrationBuilder.DropTable(
                name: "MainStdModelDict");

            migrationBuilder.CreateTable(
                name: "MainStdDataModelDict",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    ModelCode = table.Column<string>(type: "text", nullable: false),
                    ModelName = table.Column<string>(type: "text", nullable: false),
                    ModelType = table.Column<int>(type: "integer", nullable: false),
                    TopicConfigId = table.Column<Guid>(type: "uuid", nullable: false),
                    Exp = table.Column<string>(type: "text", nullable: true),
                    Ver = table.Column<int>(type: "integer", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainStdDataModelDict", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainStdDataModelDict_MainTopicConfig_TopicConfigId",
                        column: x => x.TopicConfigId,
                        principalTable: "MainTopicConfig",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "MainStdEventModelDict",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    EventCode = table.Column<string>(type: "text", nullable: false),
                    EventName = table.Column<string>(type: "text", nullable: false),
                    TopicFullPath = table.Column<string>(type: "text", nullable: false),
                    TopicConfigId = table.Column<Guid>(type: "uuid", nullable: false),
                    Exp = table.Column<string>(type: "text", nullable: true),
                    Ver = table.Column<int>(type: "integer", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainStdEventModelDict", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainStdEventModelDict_MainTopicConfig_TopicConfigId",
                        column: x => x.TopicConfigId,
                        principalTable: "MainTopicConfig",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_MainStdDataModelDict_TopicConfigId",
                table: "MainStdDataModelDict",
                column: "TopicConfigId");

            migrationBuilder.CreateIndex(
                name: "IX_MainStdEventModelDict_TopicConfigId",
                table: "MainStdEventModelDict",
                column: "TopicConfigId");

            migrationBuilder.AddForeignKey(
                name: "FK_MainStdModelAssocPhrDict_MainStdDataModelDict_StdModelDictId",
                table: "MainStdModelAssocPhrDict",
                column: "StdModelDictId",
                principalTable: "MainStdDataModelDict",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_MainStdModelAssocPhrDict_MainStdDataModelDict_StdModelDictId",
                table: "MainStdModelAssocPhrDict");

            migrationBuilder.DropTable(
                name: "MainStdDataModelDict");

            migrationBuilder.DropTable(
                name: "MainStdEventModelDict");

            migrationBuilder.CreateTable(
                name: "MainStdModelDict",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    TopicConfigId = table.Column<Guid>(type: "uuid", nullable: false),
                    Exp = table.Column<string>(type: "text", nullable: true),
                    ModelCode = table.Column<string>(type: "text", nullable: false),
                    ModelName = table.Column<string>(type: "text", nullable: false),
                    ModelType = table.Column<int>(type: "integer", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    Ver = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainStdModelDict", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainStdModelDict_MainTopicConfig_TopicConfigId",
                        column: x => x.TopicConfigId,
                        principalTable: "MainTopicConfig",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_MainStdModelDict_TopicConfigId",
                table: "MainStdModelDict",
                column: "TopicConfigId");

            migrationBuilder.AddForeignKey(
                name: "FK_MainStdModelAssocPhrDict_MainStdModelDict_StdModelDictId",
                table: "MainStdModelAssocPhrDict",
                column: "StdModelDictId",
                principalTable: "MainStdModelDict",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }
    }
}
